<template>
	<view>
		<view class="u-p-l-30 u-p-r-30">
			<u-form :model="form" :error-type="errorType" ref="uForm">
				<u-form-item label="昵称" prop="name" required>
					<u-input v-model="form.name" />
				</u-form-item>
			</u-form>
			<u-button @click="submit">提交</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				errorType:['message'],
				form: {
					name: '',
				},
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],

				},
			}
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(async valid => {
					if (valid) {
				await this.$u.api.userInfoUpdata(this.form)
				// const userInfo = await this.$u.api.userInfo()

				// //缓存用户信息
				// this.$u.vuex('vuex_user',userInfo)
				this.$u.utils.updataUser()
				this.$u.toast('更新成功')
						
					} else {
						console.log('验证失败');
					}
				});
			}
		},
		onReady() {
			this.form.name = this.vuex_user.name 
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style>

</style>
